<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="客户名称" prop="fkName">
        <el-input
          v-model="queryParams.fkName"
          placeholder="请输入客户名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
     <!-- <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['kenuo:fk:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['kenuo:fk:edit']"
        >修改</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['kenuo:fk:remove']"
        >删除</el-button>
      </el-col>
<!--      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['kenuo:fk:export']"
        >导出</el-button>
      </el-col> -->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="fkList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="客户名称" align="center" prop="fkName" />
      <el-table-column label="联系方式" align="center" prop="tel" />
      <el-table-column label="反馈内容" align="center" prop="fkContent" />
      <el-table-column label="反馈时间" align="center" prop="createTime" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleHuiFu(scope.row)"
          >回复</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['kenuo:fk:remove']"
          >删除</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="checkDetail(scope.row)"
            v-hasPermi="['kenuo:fk:edit']"
          >查看详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 添加或修改回复对话框 -->
    <el-dialog :title="huiFuTitle" :visible.sync="openHuifu" v-if="openHuifu"  width="500px" append-to-body>
      <el-form ref="HuiFuform" :model="hfform" :rules="HuifRrules" label-width="80px">
        <el-form-item label="回复" prop="replyContent">
          <el-input type="textarea" maxlength="100" show-word-limit v-model="hfform.replyContent" placeholder="请输入回复内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="HuiFusubmitForm">确 定</el-button>
        <el-button @click="HuiFuCancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 添加或修改【请填写功能名称】对话框 -->
    <el-dialog :title="title" :visible.sync="open" v-if="open" width="50%" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="反馈内容">
          <el-input
            type="textarea"
            :rows="5"
            v-model="form.fkContent"
            placeholder="请输入内容"
            disabled
           >
          </el-input>
          <!-- <textarea v-model="form.fkContent" :min-height="192"></textarea> -->
          <!-- <editor v-model="form.fkContent" :min-height="192" disabled /> -->
        </el-form-item>
        <el-form-item label="反馈图片" prop="remarkOne">
          <UploadImg v-model="form.remarkOne" uploadType="png,jpg,jpeg" :imgUrl="form.remarkOne"></UploadImg>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <!-- <el-button type="primary" @click="submitForm">确 定</el-button> -->
        <el-button @click="cancel" type="primary" >关闭</el-button>
      </div>
    </el-dialog>
    <!-- 回复详情 -->
    <el-dialog title="回复列表" :visible.sync="detailOpen" v-if="detailOpen" width="50%" append-to-body>
      <FkDtetail :fkContent="fkContent"></FkDtetail>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="detailCancel">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listFk, getFk, delFk, addFk, updateFk } from "@/api/kenuo/fk";
import UploadImg from './uploadImg'
import {
  addReply,
} from "@/api/kenuo/reply";
import FkDtetail from './fkDtetail.vue'




export default {
  name: "Fk",
  components:{
    UploadImg,
    FkDtetail
  },
  data() {
    return {
      detailOpen:false,
      huiFuTitle:"",
      hfform:{},
      // 表单校验
      HuifRrules: {
        replyContent: [{
          required: true,
          message: "回复不能为空",
          trigger: "blur"
        }],
      },
      // 表单校验
      rules: {
      },
      openHuifu:false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      fkList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        fkName: null,
        tel: null,
        fkType: null,
        fkContent: null,
        remarkOne: null,
        remarkTwo: null
      },
      imgUrl:"",
      // 表单参数
      form: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    // 关闭详情页
    detailCancel() {
      this.detailOpen = false
    },
    // 详情
    checkDetail(row) {
      this.detailOpen = true
      this.fkContent = row
    },
    /** 查询【请填写功能名称】列表 */
    getList() {
      this.loading = true;
      listFk(this.queryParams).then(response => {
        this.fkList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    HuiFuCancel(){
      this.openHuifu = false;
      this.hfform={remarkOne:"",replyContent:""}
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        fkName: null,
        tel: null,
        fkType: null,
        fkContent: null,
        createTime: null,
        remarkOne: null,
        remarkTwo: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增回复*/
    handleHuiFu(row){
      this.openHuifu = true;
      this.huiFuTitle = "回复";
      this.hfform={remarkOne:row.id,replyContent:row.replyContent}
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加【请填写功能名称】";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getFk(id).then(response => {
        this.form = response.data;
        // this.form.remarkOne='https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100','https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100';
        this.open = true;
        this.title = "查看详情";
      });
    },
    HuiFusubmitForm(){
      this.$refs["HuiFuform"].validate(valid => {
        if (valid) {
          addReply(this.hfform).then(response => {
            this.$modal.msgSuccess("操作成功");
            this.openHuifu = false;
            this.getList();
          });
        }
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateFk(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addFk(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除该数据项？').then(function() {
        return delFk(ids);
      }).then(() => {
        this.getList();

        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('kenuo/fk/export', {
        ...this.queryParams
      }, `fk_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
